//
//  LSRollingDetailViewController.m
//  LookScore
//
//  Created by wws on 2018/5/4.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSRollingDetailViewController.h"
#import "LSRollingTowView.h"
#import "LSRollingDetailView.h"
#import "LSRollingDetailCell.h"
#import "LSRecommendDetailModel.h"
@interface LSRollingDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic)UITableView *tableView;
@property(strong,nonatomic)NSMutableArray *modelArray;

@end

@implementation LSRollingDetailViewController{
    LSRollingDetailView * detailView;
    LSRollingTowView * towView;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor =LSBackGroundColor;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
-(NSMutableArray *)modelArray{
    if(!_modelArray){
        _modelArray = @[].mutableCopy;
    }
    return _modelArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =LSTitleWhiteColor;
    self.title = @"文章详情";
    [self.view addSubview:self.tableView];
    self.tableView.sd_layout
    .leftEqualToView(self.view)
    .topEqualToView(self.view)
    .rightEqualToView(self.view)
    .bottomEqualToView(self.view);
    [self ceateHeaderView];
    
    
    [self loadData:YES];
    
}

- (void)loadData:(BOOL)refresh{
    
    [LSHttpEnclosureTool GET:ExpertRecommendDetail parameters:@{@"id":self.Id} resBlock:^(id responseObject) {
        MyLog(@"%@",responseObject);
        if (refresh) {
            [self.modelArray removeAllObjects];
            
        }
        if (responseObject) {
            LSRecommendDetailModel * model = [LSRecommendDetailModel mj_objectWithKeyValues:responseObject];
            detailView.model = model;
            towView.model = model;
            [self.modelArray addObject:model];
        }
        [self.tableView reloadData];
    }];
    
}

- (void)ceateHeaderView{
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 420)];
    bgView.backgroundColor = LSBackGroundColor;
    
    detailView = [[LSRollingDetailView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 130)];
    detailView.backgroundColor = LSTitleWhiteColor;
    [bgView addSubview:detailView];
    
    towView = [[LSRollingTowView alloc] initWithFrame:CGRectMake(0, 140, LSScreenWidth, 270)];
    
    towView.backgroundColor = LSTitleWhiteColor;
    
    [bgView addSubview:towView];
    
    self.tableView.tableHeaderView = bgView;
    
}

#pragma mark 🔥 tableViewDelegate tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelArray.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LSRollingDetailCell * cell = [LSRollingDetailCell rollingDetailCellByTableView:tableView];
    cell.model = self.modelArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LSRecommendDetailModel * model = self.modelArray[indexPath.row];
    return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LSRollingDetailCell class] contentViewWidth:[tableView cellContentViewWith]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
